package com.takeoutsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.takeoutsystem.bean.Cabinet;
import com.takeoutsystem.dao.CabinetMapper;
import com.takeoutsystem.service.CabinetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> implements CabinetService {

@Autowired
CabinetMapper mapper;

    @Override
    public Page<Cabinet> selectAll(int nowPage, int pageRecordNum){
        Page<Cabinet> page=new Page<>(nowPage,pageRecordNum);
        page=this.page(page);
        return page;
    }


    @Override
    public Page<Cabinet> selectByStatus(int status, int nowPage, int pageRecordNum){
        Page<Cabinet> page=new Page<Cabinet>(nowPage,pageRecordNum);
        QueryWrapper<Cabinet> wrapper=new QueryWrapper<>();
        wrapper.eq("state_code",status);
        page=this.page(page,wrapper);
        return page;
    }


    @Override
    public Cabinet selectByCabNumber(String number){
        QueryWrapper<Cabinet> wrapper=new QueryWrapper<>();
        wrapper.eq("serial_number",number);
        return this.getOne(wrapper);
    }

    @Override
    public List<Map<String, Integer>> countByState() {
        return mapper.countByState();
    }
}
